﻿<Page
    x:Name="pageRoot"
    x:Class="CharacterMap.GroupDetailPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CharacterMap"
    xmlns:common="using:CharacterMap.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- Collection of items displayed by this page -->
        <CollectionViewSource x:Name="itemsViewSource" Source="{Binding Range.Characters}"/>
    </Page.Resources>
    <Grid x:Name="LayoutRoot" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="SelectionStates">
                <VisualState x:Name="None">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="characterPanel">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.25" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="gridView">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0.25" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation To="350" Duration="0:0:0.25" Storyboard.TargetProperty="X" Storyboard.TargetName="FlyoutTransform">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseIn" />
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="Selected">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="characterPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="gridView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
                        </ObjectAnimationUsingKeyFrames>
                        <DoubleAnimation To="0" Duration="0:0:0.25" Storyboard.TargetProperty="X" Storyboard.TargetName="FlyoutTransform">
                            <DoubleAnimation.EasingFunction>
                                <CubicEase EasingMode="EaseOut"/>
                            </DoubleAnimation.EasingFunction>
                        </DoubleAnimation>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="BusyStates">
                <VisualState x:Name="Ready"/>
                <VisualState x:Name="Busy">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="characterView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsEnabled" Storyboard.TargetName="gridView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="busyPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsActive" Storyboard.TargetName="progressRing">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="True"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="350"/>
        </Grid.ColumnDefinitions>

        <GridView x:Name="gridView" 
                AutomationProperties.AutomationId="ItemGridView"
                AutomationProperties.Name="Items In Group"
                TabIndex="1"
                Grid.RowSpan="2" Grid.ColumnSpan="2"
                Padding="120,126,120,50"
                ItemsSource="{Binding Source={StaticResource itemsViewSource}}" 
                SelectedItem="{Binding SelectedCharacter, Mode=TwoWay}">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Border Width="98" Height="98">
                        <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding}" FontSize="48" FontFamily="{Binding DataContext.SelectedFont.Family, ElementName=gridView}"/>
                    </Border>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="pageTitle" Text="{Binding Range.Name}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
            <StackPanel Orientation="Horizontal" Grid.Column="2" VerticalAlignment="Top">
                <AppBarButton x:Name="buttonCopy" Label="Copy" Icon="Copy" Command="{Binding CopyCommand}"/>
            </StackPanel>
        </Grid>

        <Grid Grid.Column="1" Grid.RowSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid Margin="0,15,0,15">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="Font: " Margin="10,0,0,0" FontSize="22" VerticalAlignment="Center"/>
                <ComboBox Grid.Column="1" Margin="10,0,10,0" VerticalAlignment="Center" ItemsSource="{Binding AllFonts}" FontSize="22" DisplayMemberPath="Name" SelectedItem="{Binding SelectedFont, Mode=TwoWay}"/>
            </Grid>
            <ScrollViewer Grid.Row="1" Margin="0,0,0,0" x:Name="characterPanel" Visibility="Collapsed" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto" HorizontalScrollMode="Disabled" Grid.RowSpan="2" Grid.Column="1">
                <Grid>
                    <Border BorderBrush="Gray" BorderThickness="2,2,0,0" Opacity=".25">
                        <Border.Background>
                            <SolidColorBrush Color="#d6dee9"/>
                        </Border.Background>
                    </Border>
                    <local:CharacterView x:Name="characterView" Margin="15,15,15,5"/>
                </Grid>
                <ScrollViewer.RenderTransform>
                    <TranslateTransform x:Name="FlyoutTransform" X="350"/>
                </ScrollViewer.RenderTransform>
            </ScrollViewer>
        </Grid>

        <Grid x:Name="busyPanel" Grid.ColumnSpan="2" Grid.RowSpan="2" Visibility="Collapsed">
            <Border Background="{ThemeResource AppBarBackgroundThemeBrush}" Opacity=".25"/>
            <ProgressRing x:Name="progressRing" IsActive="False" Width="150" Height="150"/>
        </Grid>
    </Grid>
</Page>
